package com.ybkj.o2o.sales.service.impl;


import com.ybkj.o2o.sales.entity.CouponRule;
import com.ybkj.o2o.sales.mapper.CouponMapper;
import com.ybkj.o2o.sales.mapper.CouponRuleMapper;
import com.ybkj.o2o.sales.service.CouponRuleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DefaultCouponRuleService implements CouponRuleService {

  @Autowired
  private CouponRuleMapper couponRuleMapper;
  @Autowired
  private CouponMapper couponMapper;

  @Override
  public Long insert(CouponRule couponRule) {
    return couponRuleMapper.insertRecord(couponRule);
  }

  @Override
  public void delete(Long id, String appKey) {
    couponMapper.deleteByCouponRule(id, appKey);

    couponRuleMapper.deleteByPrimaryKey(id, appKey);

  }

  @Override
  public int update(CouponRule couponRule) {
    return couponRuleMapper.updateByPrimaryKey(couponRule);
  }

  @Override
  public CouponRule findOne(Long id, String appKey) {

    return couponRuleMapper.selectByPrimaryKey(id, appKey);

  }

  @Override
  public CouponRule findByCode(String code, String appKey) {
    return couponRuleMapper.selectByCode(code, appKey);
  }

  @Override
  public List<CouponRule> selectByCompany(Long companyId, Integer offset, Integer size,
      String appKey) {
    return couponRuleMapper.selectByCompany(companyId, offset, size, appKey);
  }

  @Override
  public Long countByCompany(Long companyId, String appKey) {
    return couponRuleMapper.countByCompany(companyId, appKey);
  }

  @Override
  public List<CouponRule> selectValid(Long companyId, String appKey) {
    return couponRuleMapper.selectValidByCompany(companyId, appKey);
  }

}
